package com.pp.tourism.web.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.pp.tourism.web.mapper.ScenicSpotMapper;
import com.pp.tourism.web.pojo.ScenicRecommend;
import com.pp.tourism.web.pojo.ScenicSpot;
import com.pp.tourism.web.pojo.ScenicSpot1;
import com.pp.tourism.web.pojo.UserCommentTop;
import com.pp.tourism.web.pojo.status.ScenicStatus;
import com.pp.tourism.web.service.ScenicSpotService;
import com.pp.tourism.web.service.UserService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 景点信息表 服务实现类
 * </p>
 *
 * @author wjm
 * @since 2019-03-20
 */
@Service
public class ScenicSpotServiceImpl extends ServiceImpl<ScenicSpotMapper, ScenicSpot> implements ScenicSpotService {
    @Autowired
    private ScenicSpotMapper scenicSpotMapper;

    @Autowired
    private UserService userService;

    @Override
    public List<ScenicSpot1> queryAll(){
        return scenicSpotMapper.queryAll();
    }

    @Override
    public List<ScenicRecommend> queryHitSpot(){
        return scenicSpotMapper.queryHitSpot();
    }

    @Override
    public List<UserCommentTop> queryMaxView() {
        return scenicSpotMapper.queryMaxView();
    }

    @Override
    public List<ScenicSpot> queryAllScenics() {
        return baseMapper.selectList(new EntityWrapper<>());
    }

    @Override
    public void updateScenicsStatus(Integer scenicId, ScenicStatus scenicStatus,Double scenicPrice) {
        if (baseMapper.selectCount(new EntityWrapper<ScenicSpot>().eq("id", scenicId)) == 0) {
            throw new IllegalArgumentException("scenic is not existed");
        }
       /* if(userService.selectCount(new EntityWrapper<User>().eq("id", scenicId)) == 0){
            throw new IllegalArgumentException("user is not existed");
        }*/
        ScenicSpot scenicSpot = new ScenicSpot();
        scenicSpot.setId(scenicId);

        if (StringUtils.isNotBlank(scenicStatus.toString())) {
            scenicSpot.setScenicStatus(scenicStatus.toString());
        }
        if (scenicPrice != null) {
            scenicSpot.setScenicPrice(scenicPrice);
        }
//        scenicSpot.setUpdateBy(userId);
        scenicSpot.setUpdateTime(new Date());
        baseMapper.updateById(scenicSpot);
    }

}
